# -*- coding: utf-8 -*-

from django.core.files import File
from django.core.files.storage import Storage
from django.db import models
from django import forms
from qiniu import Auth ,put_file
import logging
logging.basicConfig(level=logging.INFO)

# Create your models here.

class Category(models.Model):
    name = models.CharField(max_length =10)
    create_time = models.DateTimeField(auto_now_add = True)
    parent = models.ForeignKey('self',default=0 , blank=True,null=True,on_delete=models.SET_NULL)
    def __str__(self):
        return self.name

    def has_child(self):
        return not self.parent == 0

class MovieInfo(models.Model):
    english_name = models.CharField(max_length=255)
    start = models.CharField(max_length=255)
    release_time = models.DateField()

class Article(models.Model):
    title = models.CharField(max_length=50)
    create_time = models.DateTimeField(auto_now_add = True)
    update_time = models.DateTimeField(auto_now = True)
    category = models.ForeignKey(Category)
    info = models.OneToOneField(MovieInfo,null=True)
    summary = models.TextField(max_length=200)
    picture = models.ImageField()
    media = models.CharField(max_length=200)
    content = models.TextField() # content of the article
    status = models.SmallIntegerField() # the status of the article. 0:un_public,1:normal,10:recommend

    def __str__(self):
        return self.title


class Picture(models.Model):
    title = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add = True)
    update_time = models.DateTimeField(auto_now = True)
    article = models.ForeignKey(Article,related_name='append_article')
    address = models.CharField(max_length=200)

    def __str__(self):
        return self.title

class Banner(models.Model):
    create_time = models.DateTimeField(auto_now_add = True)
    update_time = models.DateTimeField(auto_now = True)
    title = models.CharField(max_length=200)
    address = models.CharField(max_length=200)
    link_to = models.CharField(max_length=200)
    category = models.IntegerField()

    def __str__(self):
        return self.title


class LoginForm(forms.Form):
    name = forms.CharField(max_length=100 ,label='留言标题')
    mail = forms.EmailField(label='电子邮件')
    message = forms.CharField(label='留言内容',widget=forms.Textarea)
